<template>
	<view class="apply">
		<view style="padding: 15px;margin-bottom: 70px;">
			<view class="par-iphone">
				<view class="iphone-text">姓名</view>
				<input type="text" v-model="name" placeholder="请输入姓名" style="width: 78%;"/>
			</view>
			<view class="par-iphone">
				<view class="iphone-text">手机号码</view>
				<input type="number" v-model="mobile" placeholder="请输入联系人电话" style="width: 78%;"/>
			</view>
			<view class="par-iphone">
				<view class="iphone-text">登录密码</view>
				<input type="password" v-model="password" placeholder="输入登录密码(6-20位字母加数字组合)" style="width: 78%;"/>
			</view>
			<view class="par-iphone"  @tap="handleTap('picker3')">
				<view class="iphone-text">城市选择</view>
				<input type="type" v-model="addr" placeholder="点击按钮选择" disabled style="width: 78%;"/>
				<view class="add-but">选择地区</view>
			</view>
			<view class="par-iphone" @click="open()">
				<view class="iphone-text">街道选择</view>
				<input type="type" v-model="street" disabled placeholder="点击获取" style="width: 78%;"/>
				<view class="add-but">选择街道</view>
			</view>
			<view class="par-iphone">
				<view class="iphone-text">身份证号</view>
				<input type="type" v-model="cards" placeholder="请填写身份证号" style="width: 78%;"/>
			</view>
			<view style="color: #30344C;font-size: 13px;font-weight: bold;padding: 12px 0;">上传身份证图片</view>
			<view class="add-card">
				<view @click="upload('positive')">
					<view v-if="!positive" class="zheng">
						<image src="/static/img/zhen_car.png"></image>
						<view class="zheng-text">身份证人像面</view>
					</view>
					<view v-if="positive" class="zheng">
						<image :src="positive"></image>
					</view>	
				</view>
				<view @click="upload('negative')">
					<view v-if="!negative" class="zheng">
						<image src="/static/img/fan_car.png"></image>
						<view class="zheng-text">身份证国徽面</view>
					</view>
					<view v-if="negative" class="zheng">
						<image :src="negative"></image>
					</view>	
				</view>
			</view>
			<view style="color: #30344C;font-size: 13px;font-weight: bold;padding: 12px 0;">拍摄须知</view>
			<image src="/static/img/car_info.png" style="height:160upx;"></image>
		</view>
		
		<view>
			<view class="par-but applying" @click="hanldLogin()" v-if="status == 1">(审核中)</view>
			<view class="par-but" v-else-if="status == 2">审核通过</view>
			<view class="par-but jujue" @click="hanldLogin()" v-else-if="status == 3">申请驳回,重新申请</view>
			<view class="par-but" @click="hanldLogin()" v-else>提交申请</view>
		</view>
		
		
		
		<!--省市区-->
		<lb-picker ref="picker3"
		  v-model="value3"
		  mode="multiSelector"
		  :list="list"
		  :level="3"
		  @confirm="handleConfirm">
		</lb-picker>
		
		
		<!--街道-->
		<uni-popup ref="recash2" type="bottom" style="z-index: 9999999999;">
			<view class="cash2">
				<view class="cash2-con">
					<view class="cash2-title" v-if="addr">当前城市：{{addr}}</view>
					
					<scroll-view scroll-y show-scrollbar>
						<view class="cash2-list">
							<view class="list-item" v-for="(item,index) in streetList"  @click="confirmStreet(item)" :key="index">{{item.name}}</view>
						</view>
					</scroll-view>
				</view>
				
				<!-- <view class="cash-but3">
					<view class="but-left3" @click="">
						取消
					</view>
					<view class="but-right3" @click="confirmStreet()" >
						确定
					</view>
				</view> -->
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	import LbPicker from '@/components/lb-picker'
	import areaData from 'libs/area-data-min'
	export default {
		data() {
			return {
				value3: [],
				list: areaData,
				mobile:wx.getStorageSync('wechatMobile'),
				password:'',
				name:'',
				cards:'',//身份证号
				positive:'',//身份证正面
				negative:'',//身份证反面
				streetId:'',
				street:'',
				addr:'',
				streetList:[],
				
				status:'',
				riderInfo:{},//骑手信息
			}
		},
		components: {
			LbPicker
		},
		onLoad(){
			
		},
		onShow(){
			this.getRiderApply()
		},
		methods: {
			upload(type){
			     let that = this;
			     uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						const tempFilePaths = res.tempFilePaths;
						 // that.qrcode = tempFilePaths[0];
						 console.log("tempFilePaths[0]",tempFilePaths[0])  //能够打印出选中的图片
						 uni.uploadFile({
							url: that.$urlConfig+'other/uploads',
							filePath: tempFilePaths[0],
							fileType: 'image',
							name: 'file',
							headers: {
								'Accept': 'application/json',
								'Content-Type': 'application/json'
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes)
								let data = JSON.parse(uploadFileRes.data)
								uni.showToast({
									title: data.msg,
									icon: 'none'
								})
								if(type == 'positive'){
									that.positive = data.data
								}else{
									that.negative = data.data
								}
							},
							fail: (error) => {
								if (error && error.response) {
									console.log('error.response', error.response)
									uni.showToast({
										title: error.response,
										icon: 'none'
									})
								}
							},
							complete: () => {
								setTimeout(function() {
									uni.hideLoading();
								}, 250);
							},
						});
					},
					error : function(e){
					 console.log(e);
					}
			    });
			},
			// //选择街道
			// changeStreet(item){
			// 	this.streetId = item.id
			// },	
			//确认选择街道
			confirmStreet(item){
				this.street = item.name
				this.streetId = item.id
				this.$refs.recash2.close()
			},
			getRiderApply(){
				this.$http.rider_apply_info().then(res => {
					console.log(res)
					if(res.data){
						this.riderInfo = res.data
						this.addr = this.riderInfo.province_text+this.riderInfo.city_text+this.riderInfo.area_text
						this.mobile = this.riderInfo.mobile
						this.name = this.riderInfo.name
						this.cards = this.riderInfo.cards
						this.positive = this.riderInfo.positive
						this.negative = this.riderInfo.negative
						this.status = this.riderInfo.status
						uni.setStorageSync('riderStatus',this.status)
						if(this.status == 2){
							if(uni.getStorageSync('riderToken')){
								uni.redirectTo({
									url:'/pages/member/horseman/Index'
								})
							}else{
								uni.redirectTo({
									url:'/pages/member/horseman/login'
								})
							}
						}
						this.street = this.riderInfo.street_text
						this.streetId = this.riderInfo.street
						this.value3 = [
							{
								label:this.riderInfo.province_text,
								value:this.riderInfo.province
							},
							{
								label:this.riderInfo.city_text,
								value:this.riderInfo.city
							},
							{
								label:this.riderInfo.area_text,
								value:this.riderInfo.area
							}
						]
					}
				})
			},
			getStreet(id){
				this.$http.getstreet({id:id}).then(res => {
					console.log(res)
					this.streetList = res.data
				})
			},
			//提交申请
			hanldLogin(){
				if(!this.name){
					uni.showToast({
						title:'请输入姓名',
						icon:'none'
					})
					return
				}
				if(!this.mobile){
					uni.showToast({
						title:'请输入手机号码',
						icon:'none'
					})
					return
				}
				if(!this.password){
					uni.showToast({
						title:'请输入登录密码',
						icon:'none'
					})
					return
				}
				if (!(/^(?=.*\d)(?=.*[a-zA-Z]).{6,20}$/.test(this.password))) {
					uni.showToast({
						title:'登录密码为6-20位字母数字组合',
						icon:'none'
					})
					return
				}
				if(this.value3.length == 0){
					uni.showToast({
						title:'请选择城市',
						icon:'none'
					})
					return
				}
				if(!this.street){
					uni.showToast({
						title:'请选择街道',
						icon:'none'
					})
					return
				}
				if(!this.cards){
					uni.showToast({
						title:'请输入身份证号',
						icon:'none'
					})
					return
				}
				let province = this.value3[0].value
				let city = this.value3[1].value
				let area = this.value3[2].value
				let formData = {
					mobile:this.mobile,
					password:this.password,
					name:this.name,
					cards:this.cards,
					positive:this.positive,
					negative:this.negative,
					province:province,
					city:city,
					area:area,
					street:this.streetId
				}
				this.$http.rider_apply(formData).then(res => {
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					if(res.code == 0){
						setTimeout(() => {
							this.getRiderApply()
						},1000)
					}
				})
			},
			//省市区
			handleTap (picker) {
				this.$refs[picker].show()
			},
			handleConfirm (item) {
				console.log('confirm::', item)
				this.value3 = item.item
				this.addr = this.value3[0].label+this.value3[1].label+this.value3[2].label
				this.getStreet(this.value3[2].value)
			},
			//街道
			open() {
				if(!this.addr){
					uni.showToast({
						title:'请先选择省市区',
						icon:'none'
					})
					return
				}
				if(this.value3.length>0){
					this.getStreet(this.value3[2].value)
				}	
				this.$refs.recash2.open()
			}
		}
	}
</script>

<style scoped>
	.apply{
		width: 100%;
	}
 .par-iphone:nth-of-type(1){
	 margin: 0;
 }
.par-iphone{
	display: flex;
	flex-direction: row;
	background-color: rgba(187, 187, 187, 0.1);
	height: 43px;
	border-radius: 5px;
	align-items: center;
	margin: 15px 0;
	position: relative;
}

.iphone-text{
color: #242424;
font-size: 14px;
padding: 0 24upx;
min-width: 158upx;
}
.uni-input-placeholder{
	font-size: 12px;
	color: #898989;
}
.add-but{
	border-radius: 15px;
	border: 1px solid #FF6001;
	color: #FF6001;
	font-weight: bold;
	height: 22px;
	text-align: center;
	line-height: 22px;
	min-width: 60px;
	margin-right: 10px;
	/* position: absolute; */
	/* right: 10px; */
}
.par-but{
	height:96upx;
	
	background: linear-gradient(90deg, #FFC500 0%, #FF5F01 100%);
	box-shadow: 0px 4upx 8upx 0px #FFAB71;
	border-radius:48upx;
	line-height: 96upx;
	text-align: center;
	font-size: 16px;
	color: #FFFFFF;
	margin: 50px auto 0 auto;
	position: fixed;
	bottom: 0;
	width: 100%;
	z-index: 9;
}
.par-but.applying{
	background:#2B2A29;
	color:  #FFFFFF;
	box-shadow:none
}
.par-but.jujue{
	color: #FE4744;
	background:#2B2A29;
	box-shadow:none
}
.add-card{
	display: flex;
	flex-direction: row;
}
.zheng{
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	margin-right: 32px;
}
	
.zheng image{
	width: 104px;
	height: 61px;
}
.zheng-text{
	color: #86868B;
	padding: 12px 0;
}

/*街道*/
.cash2 {
		height: 942upx;
		background: rgba(255, 255, 255, 1);
		border-radius: 25px 25px 0px 0;
	}

	.cash-but3 {
		display: flex;
		flex-direction: row;
		position: fixed;
		bottom: 0;
		justify-content: space-between;
		width: 100%;
	}

	.but-left3 {
		background-color: rgba(211, 212, 217, 1);
		width: 50%;
		height: 48px;
		text-align: center;
		font-size: 16px;
		color: rgba(57, 61, 84, 1);
		font-weight: bold;
		line-height: 48px;
	}

	.but-right3 {
	
background: linear-gradient(90deg, #FFC500 0%, #FF5F01 100%);
box-shadow: 0px 4upx 8upx 0px #FFAB71;
		width: 50%;
		height: 48px;
		text-align: center;
		font-size: 16px;
		color: #fff;
		font-weight: bold;
		line-height: 48px;
	}
		
	.cash2-title{
		font-weight: bold;
		font-size: 16px;
		text-align: center;
		padding: 25px 0;
	}
.cash2-list{
	display: flex;
	flex-direction: column;
	height: 370px;
	padding-bottom: 10px;
}
	
.list-item{
	color: #30344C;
	font-size: 14px;
	padding: 15px 0;
	border-bottom: 1px solid #D9D9DB;
	text-align: center;
}
 .list-item:nth-of-type(1) { 
	 	border-top: 1px solid #D9D9DB;
 }
</style>
